<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	const Box = function(userName,age){
		this.userName = userName;
		this.age = age;
		return 1;//{a:1,b:2};
	}
	// constr:构造函数
	function myNew(constr){
		// 1- 创建一个空的对象，增加属性__proto__指向到构造函数的Prototype属性。
		const obj = {};
		obj.__proto__ = constr.prototype;
		// 2- 调用构造函数，并将构造函数内的this指向到创建的空对象。
		const result = constr.apply(obj,Array.from(arguments).slice(1));
		if(typeof result === "object" || typeof result === "function") return result;
		return obj;
	}
	const obj = myNew(Box,"zhangsan",12);// new Box("zhangsan",12);
	console.log(obj.__proto__ === Box.prototype);
	console.log(obj.constructor === Box);
	console.log(obj);
	
</script>
</html>